using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;

namespace MIMPWinForms.SpriteDisplays
{
    /// <summary>
    /// Use this class to draw a semi-transparent rectangle with some text on it.
    /// Intended for information that "pops up" temporarily.
    /// </summary>
    public class PopupBox
    {
        Texture2D box;
        SpriteFont font;

        string text;
        Vector2 origin;
        /// <summary>
        /// Get or set the text to draw in the popup box.
        /// </summary>
        public string Text {
            get { return text; }
            set { text = value; }
        }
        /// <summary>
        /// Specifies the center pixel of the popup box.
        /// </summary>
        public Vector2 Origin {
            get { return origin; }
            set { origin = value; }
        }

        bool isVisible;
        /// <summary>
        /// True if this PopupBox should be drawn, false otherwise.
        /// </summary>
        public bool IsVisible {
            get { return isVisible; }
            set { isVisible = value; }
        }

        public PopupBox(string text, Vector2 origin) {
            this.text = text;
            this.origin = origin;
        }

        public void LoadContent(ContentManager content) {
            box = content.Load<Texture2D>("Sprites\\blank");
            font = content.Load<SpriteFont>("Fonts\\PopupFont");
        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch) {
            if (!isVisible) { return; }

            Vector2 size = font.MeasureString(text) + new Vector2(4, 4);
            //Vector2 origin = center - (size / 2);
            Rectangle bounds = new Rectangle((int)origin.X, (int)origin.Y, (int)size.X, (int)size.Y);
            spriteBatch.Begin();
            Color boxColor = new Color(255, 255, 255, 150);
            spriteBatch.Draw(box, bounds, boxColor);
            spriteBatch.DrawString(font, text, origin + new Vector2(2, 2), Color.Black);
            spriteBatch.End();
        }
    }
}
